package com.dlc.felear.xiaoensale.dao;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.dlc.felear.xiaoensale.entity.MenuRecordInfo;
import com.j256.ormlite.dao.Dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MenuRecordInfoDao {
    private static final String TAG = "MenuRecordInfoDao";
    private Dao<MenuRecordInfo, Integer> PipeInfoDao;

    /**
     * 构造方法
     * 获得数据库帮助类实例，通过传入Class对象得到相应的Dao
     *
     * @param context
     */
    public MenuRecordInfoDao(Context context) {
        try {
            PipeInfoDao = DetailDataOpenHelper.getInstance(context).getDao(MenuRecordInfo.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    /**
     * 添加一条记录
     *
     * @param PipeInfo
     */
    public int add(MenuRecordInfo PipeInfo) {
        int temp = -1;
        try {
            PipeInfoDao.create(PipeInfo);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
            return temp;
        }

        return temp;
    }


    public void addAll(List<MenuRecordInfo> list) {
        if (list == null) {
            return;
        }
        for (MenuRecordInfo MenuRecordInfo : list) {
            add(MenuRecordInfo);
        }
    }

    /**
     * 删除一条记录
     *
     * @param PipeInfo
     */
    public void delete(MenuRecordInfo PipeInfo) {
        try {
            PipeInfoDao.delete(PipeInfo);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询所有记录
     *
     * @return
     */
    public List<MenuRecordInfo> queryForAll() {
        List<MenuRecordInfo> PipeInfos = new ArrayList();
        try {
            PipeInfos = PipeInfoDao.queryForAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return PipeInfos;
    }

}
